from pydantic_settings import BaseSettings
from typing import Optional, Dict, Any
from dotenv import load_dotenv

load_dotenv()

class Settings(BaseSettings):
    # 基础配置
    PROJECT_NAME: str = "AI Tech API"
    PROJECT_DESCRIPTION: str = """
    AI Tech API 是一个基于 FastAPI 的 RESTful API 服务。
    
    ## 功能特点
    
    * 📚 文档管理
    * 📝 章节管理
    * ❓ 题目生成
    * 🔄 自动迁移
    
    ## API 版本
    
    当前版本: v1
    """
    VERSION: str = "1.0.0"
    DEBUG: bool = True
    API_V1_STR: str = "/api/v1"
    
    # 数据库配置
    DATABASE_URL: str = "mysql://root:123456@localhost:3306/aitech"  # 修改为MySQL连接串
    
    # LLM配置
    LLM_PROVIDER: str = "openai"  # openai, local
    LLM_API_KEY: str = ""
    LLM_API_BASE: str = "https://api.openai-proxy.com/v1"  # 用于自定义endpoint
    LLM_MODEL: str = "gpt-4o"

    # 新添加的配置
    AUTO_MIGRATE: bool = True  # 在生产环境中设置为 False

    class Config:
        case_sensitive = True
        env_file = ".env"

    def get_tortoise_config(self) -> Dict[str, Any]:
        """获取Tortoise ORM配置"""
        return {
            "connections": {"default": self.DATABASE_URL},
            "apps": {
                "models": {
                    "models": ["app.models", "aerich.models"],
                    "default_connection": "default",
                }
            },
            "use_tz": False,
            "timezone": "Asia/Shanghai"
        }

settings = Settings()

# 添加 TORTOISE_ORM 配置作为独立变量
TORTOISE_ORM = settings.get_tortoise_config() 